//------------------------------------------------------------------------------------------------- 
// <copyright file="SPFolderHelper.cs" company="Collaboris">
// Copyright (c) Collaboris.  All rights reserved.
// </copyright>
// <summary>Defines the SPFolderHelper type.</summary>
//-------------------------------------------------------------------------------------------------
// TODO: Remove the Dependency on Name Value Pairs
namespace Collaboris.SharePoint.Wss.Administraton
{
    /// <summary>
    /// Provides Helper Utilities for SP Folders
    /// </summary>
    public class SPFolderHelper : WssHelperBase
    {
        ////public NameValueStringPairCollection GetFolders(SPWeb web,
        ////                                                string include,
        ////                                                string exclude,
        ////                                                bool recursive)
        ////{
        ////    NameValueStringPairCollection _folderList = null;
        ////    try
        ////    {                
        ////        string _url = string.Empty;
        ////        string _name = string.Empty;
        ////        Regex _nameMatchInclude = new Regex(include,RegexOptions.IgnoreCase);
        ////        Regex _nameMatchExclude = new Regex(exclude,RegexOptions.IgnoreCase);

        ////        _folderList = new NameValueStringPairCollection();
        ////        NameValueStringPair _folderNameValuePair = null;
                
        ////        foreach (SPFolder _spFolder in web.Folders)
        ////        {                    
        ////            _name = _spFolder.Name;                    

        ////            if (_nameMatchInclude.IsMatch(_name))
        ////            {
        ////                if (exclude.Length > 0)
        ////                {
        ////                    if (!_nameMatchExclude.IsMatch(_name))
        ////                    {
        ////                        //_folderNameValuePair = new NameValueStringPair(_spFolder.UniqueId.ToString(), _spFolder.ServerRelativeUrl);
        ////                        //_folderList.Add(_folderNameValuePair);

        ////                        NameValueStringPairCollection _nvspCollection = new NameValueStringPairCollection();
        ////                        _nvspCollection = GetSubFolders(_spFolder);
        ////                        for (int i = 0; i < _nvspCollection.Count; i++)
        ////                        {
        ////                            _folderList.Add(_nvspCollection[i]);
        ////                        }
        ////                    }
        ////                }
        ////                else
        ////                {
        ////                    //_folderNameValuePair = new NameValueStringPair(_spFolder.UniqueId.ToString(), _spFolder.ServerRelativeUrl);
        ////                    //_folderList.Add(_folderNameValuePair);

        ////                    NameValueStringPairCollection _nvspCollection = new NameValueStringPairCollection();
        ////                    _nvspCollection = GetSubFolders(_spFolder);
        ////                    for (int i = 0; i < _nvspCollection.Count; i++)
        ////                    {
        ////                        _folderList.Add(_nvspCollection[i]);
        ////                    }
        ////                }
        ////            }
        ////        }

        ////        if (recursive)
        ////        {                    
        ////            NameValueStringPairCollection _folderSubsiteList = null;
        ////            foreach (SPWeb spWeb in web.Webs)
        ////            {
        ////                _folderSubsiteList = GetFolders(spWeb, include, exclude, recursive);
        ////                for(int i = 0; i < _folderSubsiteList.Count ; i++)
        ////                {                          
        ////                    _folderList.Add(_folderSubsiteList[i]);
        ////                }

        ////                spWeb.Dispose();
        ////            }
        ////        }
        ////    }
        ////    catch (Exception ex)
        ////    {
        ////        throw new Exception("Failed to get the folder list for the site :" + web.Title,ex);
        ////    }

        ////    return _folderList;
        ////}


        #region private methods
        //private NameValueStringPairCollection GetSubFolders(SPFolder spFolder)
        //{
        //    NameValueStringPairCollection _nvspCollection = new NameValueStringPairCollection();
        //    NameValueStringPair _temp = new NameValueStringPair(spFolder.UniqueId.ToString(), spFolder.Url);
        //    _nvspCollection.Add(_temp);
            
        //    for (int i = 0; i < spFolder.SubFolders.Count; i++)
        //    {
        //        NameValueStringPairCollection _nvspSubFolderCollection = GetSubFolders(spFolder.SubFolders[i]);
        //        for (int j = 0; j < _nvspSubFolderCollection.Count; j++)
        //        {                    
        //            _nvspCollection.Add(_nvspSubFolderCollection[j]);
        //        }
        //    }
            
        //    return _nvspCollection;
        //}
        #endregion
    }
}